package com.nchu.learn.netty.model;

import com.google.common.collect.Maps;
import com.nchu.learn.netty.enums.MessageTypeEnum;
import lombok.Data;

import java.util.Collections;
import java.util.Map;

/**
 * netty自定义消息体格式
 *
 * @author fujianjian
 * @project self-learning
 * @date 2020/1/16 10:21
 */
@Data
public class Message {

    private int magicNumber;
    private byte mainVersion;
    private byte subVersion;
    private byte modifyVersion;

    private String sessionId;
    private MessageTypeEnum messageType;

    private Map<String, String> attachments = Maps.newHashMap();
    private String body;

    public Map<String, String> getAttachments() {
        return Collections.unmodifiableMap(this.attachments);
    }

    public void setAttachments(Map<String, String> attachments) {
        if (attachments != null) {
            this.attachments.clear();
            this.attachments.putAll(attachments);
        }

    }

    public void addAttachment(String key, String value) {
        this.attachments.put(key, value);
    }
}
